package com.monkey.core.domain.role;

import com.monkey.core.domain.BaseEntity;
import com.monkey.core.plugin.dto.MonkeyDto;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * 角色表
 */
@Entity
@Table(name = "sys_role")
@DynamicUpdate
@DynamicInsert
public class Role extends BaseEntity<Long> {

    /**
     * 前端显示名称
     */
    @Column(unique = true)
    private String name;
    /**
     * 系统中验证时使用的角色标识
     */
    @Column(name = "role", unique = true)
    private String role;

    /**
     * 详细描述
     */
    private String description;

    public Role() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * 根据MonkeyDto 构建一个对象，根据具体情况自行实现，在新增的时候使用
     */
    public static Role createFromMonkeyDto(MonkeyDto monkeyDto) {
        Role instance = new Role();
        //根据具体情况自行实现
        instance.setName(monkeyDto.getString("name"));
        instance.setRole(monkeyDto.getString("role"));
        instance.setDescription(monkeyDto.getString("description"));
        return instance;
    }

    public static void modifyFromMonkeyDto(Role instance, MonkeyDto monkeyDto) {
        //根据具体情况自行实现
        instance.setName(monkeyDto.getString("name"));
        instance.setRole(monkeyDto.getString("role"));
        instance.setDescription(monkeyDto.getString("description"));
    }

}
